<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<div class="panel">
    <div id="classes-heading" class="panel-heading bg-gray-light">
        <h3 class="panel-title">指标评测<span id="title-duty-name-targetEvaluate" class="text-muted"> | </span></h3>
    </div>

    <div class="panel-body">
        <form th:id="'form_targetEvaluate_input'+${targetEvaluate?.id}" class="form-horizontal" autocomplete="off">
            <input type="hidden" name="keyId" th:value="${targetEvaluate?.id}">
            <input type="hidden" name="targetId" th:value="${target!=null ? target.id : targetEvaluate?.targetId}">
            <input type="hidden" name="flowDutyId">
            <input type="hidden" name="flowDutyName">
            <input type="hidden" name="detailJson">

            <p th:if="${targetEvaluate?.detailList==null || #lists.size(targetEvaluate?.detailList) == 0}">请补充系统字典评测类目</p>

            <th:block th:each="dict,i : ${targetEvaluate?.detailList}">

                <div class="form-group" data-title="evaluateDetail">
                    <label class="col-md-3 control-label">[[${dict.dictName}]]<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-8">
                        <div data-title="evaluateDetail-radio" class="radio" th:id="${dict.id}" th:data-dict-id="${dict.dictId}">
                            <th:block th:each="index:${#numbers.sequence(-5,5)}" th:if="${index != 0}">
                                <input type="radio" th:name="'score_'+${i.index}" th:id="'score_'+${i.index}+'_'+${index}" th:value="${index}" class="magic-radio" th:checked="${dict.score == index}" >
                                <label th:for="'score_'+${i.index}+'_'+${index}" th:text="${index}"></label>
                            </th:block>
                        </div>
                    </div>
                </div>

            </th:block>

        </form>
    </div>
</div>

<script th:inline="javascript">
    var keyId_targetEvaluate = [[${targetEvaluate?.id}]];
    var flowData_targetEvaluate = {
        keyId : keyId_targetEvaluate ? keyId_targetEvaluate : "create",
        formId : "form_targetEvaluate_input"+[[${targetEvaluate?.id}]],
        path : "com.hanqian.kepler.core.entity.primary.core.TargetEvaluate",
        titleId : "title-duty-name-targetEvaluate"
    };
    var $form = $("#"+flowData_targetEvaluate.formId);

    $(function(){
        __flow_duty_handle(flowData_targetEvaluate);
        __flow_button_input_handle(flowData_targetEvaluate, fn_targetEvaluate_save, fn_targetEvaluate_commit);
        fn_targetEvaluate_input_validate();
        // __layX_adapt_height(flowData_targetEvaluate.keyId);
    });


    //表单验证
    function fn_targetEvaluate_input_validate(){
        __init_validate(flowData_targetEvaluate.formId, {
            rules : {
                score_0 : {required : true},
                score_1 : {required : true},
                score_2 : {required : true},
                score_3 : {required : true},
                score_4 : {required : true}
            }
        });
    }

    //保存方法
    function fn_targetEvaluate_save(){
        var url = "targetEvaluate/save";

        createJsonData();
        __confirm_dialog("", "确认保存吗？", function(){
            __form_save(flowData_targetEvaluate.formId, ctx + url, function(data){
                if(data && data.state === 1){
                    __flow_close_layx(flowData_targetEvaluate);
                }
            })
        })
    }

    //提交方法
    function fn_targetEvaluate_commit(){
        if(!$("#" + flowData_targetEvaluate.formId).valid()){
            return false;
        }
        createJsonData();
        __confirm_dialog("", "确认提交吗？", function(){
            __form_save(flowData_targetEvaluate.formId, ctx + "targetEvaluate/commit", function(data){
                if(data && data.state === 1){
                    __flow_close_layx(flowData_targetEvaluate);
                }
            })
        })
    }

    //创建评分json
    function createJsonData(){
        var arr = [];
        $("div[data-title='evaluateDetail-radio']").each(function(i){
            var $div = $(this);
            var id = $div.attr("id");
            var dictId = $div.attr("data-dict-id");
            var score = $(":radio[name='score_"+i+"']:checked").val();
            arr.push({
                id : isNotNull(id) ? id : "",
                dictId : isNotNull(dictId) ? dictId : "",
                score : isNotNull(score) ? score : ""
            })
        });
        $("input[name='detailJson']").val(JSON.stringify(arr));
    }

</script>

</html>